package com.tuyrt.hi.ui.app.demo.tab

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.tuyrt.hi.ui.app.R
import com.tuyrt.hi.ui.tab.top.HiTabTopInfo
import com.tuyrt.hi.ui.tab.top.HiTabTopLayout

/**
 * author: Administrator on 2021/4/29.
 * desc:
 */
class HiTabTopDemoActivity : AppCompatActivity() {
    var tabsStr = arrayOf(
        "热门",
        "服装",
        "数码",
        "鞋子",
        "零食",
        "家电",
        "汽车",
        "百货",
        "家居",
        "装修",
        "运动"
    )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_hi_tab_top_demo)

        initTabTop()
    }

    private fun initTabTop() {
        val tabTopLayout = findViewById<HiTabTopLayout>(R.id.tab_top_layout)
        val defaultColor = resources.getColor(R.color.tabDefaultColor)
        val tintColor = resources.getColor(R.color.tabTintColor)
        val infoList = ArrayList<HiTabTopInfo<*>>()
        for (tabName in tabsStr) {
            val info = HiTabTopInfo<Int>(tabName, defaultColor, tintColor)
            infoList += info
        }
        tabTopLayout.inflateInfo(infoList)
        tabTopLayout.addOnTabSelectedChangeListener { _, _, nextInfo ->
            Toast.makeText(this@HiTabTopDemoActivity, nextInfo.name, Toast.LENGTH_SHORT).show()
        }
        tabTopLayout.defaultSelected(infoList[0])
    }
}